#pragma Once
#include "TcpServer.hpp"
#include <memory>
#include"Calculator.hpp"

Calculator calculator;

void DefaultOnMessage(std::weak_ptr<Connection> conn)
{
    if (conn.expired())
        return;
    auto connection = conn.lock();
    // 上层处理数据
    std::string response_str = calculator.Handler(connection->GetInBuffer()); // 我们的业务逻辑比较简单，没有特别耗时的操作
    if (response_str.empty())
        return;
    lg(Debug, "%s", response_str.c_str());

    // 将response_str 发送到Connection类中的 _outbuffer 中
    connection->AppendOutbuffer(response_str);

    auto tcpserver = connection->_tcp_server_ptr.lock();
    tcpserver->Sender(connection);
}

int main()
{
    std::shared_ptr<TcpServer> svr(new TcpServer(8080,DefaultOnMessage));
    svr->Init();
    svr->Start();
    return 0;
}
